﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Edge {
    public Point pointA { get; internal set; }
    public Point pointB { get; internal set; }

    public Room roomA { get; internal set; }
    public Room roomB { get; internal set; }

    public int Length { get; internal set; }

    //private Point[] beacons = null;

    private List<Point> route = null;

    private Point door = null;
    private Point pointBeforeDoor = null;
    private Point pointAfterDoor = null;


    public Edge(Room a, Room b)
    {
        roomA = a;
        roomB = b;
        pointA = a.GetCenter();
        pointB = b.GetCenter();
    }

    //public void AddBeacon(Point beacon)
    //{
    //    beacons[beacons.Length] = beacon;
    //}

    public void SetRoute(List<Point> pointList)
    {
        route = pointList;
        Length = pointList.Count;
    }
    public List<Point> GetRoute()
    {
        return route;
    }

    public bool Equals(Edge edge)
    {
        return ((this.pointA.Equals(edge.pointA) || this.pointA.Equals(edge.pointB)) && (this.pointB.Equals(edge.pointA) || this.pointB.Equals(edge.pointB)));
    }

    public void SetDoor(Point _door)
    {
        door = _door;
        SetDoorNeighbourPoint();
    }

    private void SetDoorNeighbourPoint()
    {
        int indexOfDoor = route.IndexOf(door);
        pointBeforeDoor = route[indexOfDoor - 1];
        pointAfterDoor = route[indexOfDoor + 1];
        roomA.SetDoorPlaceholderPosition(pointBeforeDoor);
        roomB.SetDoorPlaceholderPosition(pointAfterDoor);

    }

}
